<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="${ctx}/css/common.css" />
	<jsp:include page="../inc.jsp"></jsp:include>
	<jsp:include page="../head.jsp"></jsp:include>
<meta http-equiv="X-UA-Compatible" content="edge" />
<title>订单管理-切位订单</title>
<style>
		select,input{
			height:18px;
			border:1px solid #77b2e0;
			border-radius: 3px;
		}
		body {
			margin:0 15px;
		}
		#box{
			margin:0 auto;		
		}
		.searchBox{
			width:1030px;
			height:20px;
			padding-bottom:20px;
			margin-left:15px;
			margin-top:15px;
			
		}
		.search input{
			margin-right:20px;
			border:1px solid #77b2e0;
		}
		select{
			height:20px;
			margin-right:20px;	
			border:1px solid #77b2e0;				
		}
		.query{
			float:right;
		}
		.searchDetail{
			border-collapse: collapse;
			text-align: center;
			border:1px solid #dedede;
		}
		.searchDetail th{
			font-size: 12px;
			font-weight: normal;
			border:1px solid #dedede;
			height:30px;
			color:#3989c8;
			/* min-width: 10%; */
		}
		.searchDetail td{
			border:1px solid #dedede;
			height:30px;
			min-width:40px;
			text-align:center;
			/* padding:0 5px; */
		}
		/*使按钮居中*/
		.autoBox{
			width:250px;
			height:26px;
			margin:15px auto; 
		}
		.searchDetail .autoBoxOne{
			width:100px;
		}
		.searchDetail .autoBoxTwo{
			width:180px;
		}
		.searchDetail .operation{
			min-width:100px;
		}
		.total{
			color:red;
			margin-left:50px;
		}
		input::-ms-clear{display:none;}
		.pageUl li{
			float:left;
			cursor:pointer;			
		}
	</style>
<script type="text/javascript">
	$(function() { 
		//进入页面时  加载列表项
	//	 progressLoad();
		getajax();
		//点击查询  加载表格项
		$("#orderqueryBtn").click(function(){
			getajax();
		});
		
		//分页		
		//改变每页显示多少条记录
		$('.pageSize').change(function(){
			var pageSize = $('.pageSize').val()
			var pageNum = $('.pageNum').val('1')
			getajax()
		})
		
		//首页
		$('.firstPage').click(function(){
			var pageNum = $('.pageNum').val('1');
			getajax();
		})
		//前一页
		$('.prePage').click(function(){
			var pageNum = $('.pageNum').val();	
			if(pageNum == 1){
				$('.pageNum').val('1');
			}else{
				$('.pageNum').val(pageNum-1);
			}
			getajax();
		});
		//输入搜索
		$('.pageNum').keypress(function(){
				if(event.keyCode ==13){			
					if($('.pageNum').val()<=totalPage){
						var pageNum = $('.pageNum').val();
						//alert(pageNum)
						getajax();
					}else{
						var pageNum = $('.pageNum').val(totalPage);
						getajax();
					};					
				};
			});
		
		//下一页
		$('.nextPage').click(function(){
			var pageNum = $('.pageNum').val();	
			if(pageNum == totalPage){
				$('.pageNum').val(totalPage);
			}else{
				$('.pageNum').val(pageNum-0+1);
			}			
			getajax();
		})
		//最后一页
		$('.lastPage').click(function(){
			var pageNum = $('.pageNum').val(totalPage);
			getajax();
		})
		//刷新
		$('.reflesh').click(function(){
			window.location.reload();
		})
		
	}); 
	//封装函数  实现查询订单功能
	//全局变量 总页数
	var totalPage;
	function getajax(){
		var pageSize = $('.pageSize').val();
		var pageNum = $('.pageNum').val(); 
		var conNo=$("#conNo").val();
		var conStatus=$("#conStatus").val();
		var toStartAirportCode=$("#_startCity").val();
		var toEndAirportCode=$("#_endCity").val();
		var toStartDate=$("#_startTime").datebox('getValue');
		//发送ajax请求  根据参数返回值
		if(typeof(toStartAirportCode) == 'undefined'){
			toStartAirportCode = "";
		}
		if(typeof(toEndAirportCode) == 'undefined'){
			toEndAirportCode = "";
		}
		$.get("${ctx}/search/contractList?conNo="
				+conNo+"&conStatus="
				+conStatus+"&toStartAirportCode="
				+toStartAirportCode+"&toEndAirportCode="
				+toEndAirportCode+"&toStartDate="
				+toStartDate+"&temp="
				+Math.random()+"&page="
				+pageNum+"&rows="
				+pageSize+"&msgTime=${message.startTime}"+"&msgStatus=${message.status}",function(data){
			totalPage = Math.ceil(data.pages);
			$('.totalRecord').html(data.total);
			if(data.list.length==0){
				$('.totalPage').html("1");
			}else{
				$('.totalPage').html(totalPage);
			}
			
			$('.recordForm').html(Number((pageSize*pageNum)-Number(pageSize)+1));			
			var recordTo = Number(pageSize*pageNum);
			if(recordTo>=data.total){
				$('.recordTo').html(data.total)
			}else{
				$('.recordTo').html(recordTo)
			}; 
			$("#searchDetail  tr:not(:first)").empty();
			 
			var str = "";
			
			for(var i=0;i<data.list.length;i++){
//				var data=data.list[i]; //获得本条合同的数据对象
				var deposit=data.list[i].deposit; //押金
				var conNo=data.list[i].conNo;//合同号
				var conStatus=data.list[i].conStatus;//合同状态
			//	var payOverTime=data.payOverTime.replace(" ","="); //支付截止时间
				var payOverTime=CommonConverter.toEmptyString(data.list[i].payOverTime);   //支付截止时间
				var prefix_arr=data.list[i].orderList; //得到小订单数组数据
				var tablebutton="";
				if(conStatus==2){  //待支付状态时 显示支付押金按钮
					tablebutton="<div class='autoBox autoBoxOne'><button class='mynewBtn' onclick=payDeposit('"+conNo+"','"+deposit+"','"+payOverTime.replace(" ","=")+"')>支付押金</button></div>";
				
				}
				var moreDetail="";//更多详情按钮拼接
					
					moreDetail="<a  href='javascript:void(0)' style='float:right;color:#3989c8;text-decoration:underline' onclick=moreDetail('"+conNo+"','"+conStatus+"','"+payOverTime.replace(" ","=")+"'); >更多详情</a>";
				
				var x=0;
				//str+="<tr><td colspan=11>合同号：<span>"+data.list[i].conNo+"</span>合同状态：<span>"+data.list[i].conStatus+"</span>支付截至时间：<span>"+data.list[i].conNo+"</span></td></tr>"			
				str+="	<tr><td colspan='11' style='text-align: left;background:#f2f2f2;padding-right:60px;'>";
				str+="    合同号："+conNo+"   合同状态："+CommonConverter.toContractStatusStr(conStatus)+"    支付截止时间："+payOverTime+moreDetail;
				str+="	</td></tr>";
				for(var j=0;j<data.list[i].orderList.length;j++){					
					for(var m=0;m<data.list[i].orderList[j].list.length;m++){
						x++										
						var length = data.list[i].orderList[j].list.length
						var length1 = data.list[i].orderList.length
						if(m==0){
							str+="<tr>"+
								"<td rowspan="+length+">"+data.list[i].orderList[j].list[m].orderNo+"</td>"
						}else{
							str+=""
						}						
							str+="<td>"+data.list[i].orderList[j].list[m].airlineNumber+"</td>"+
								"<td>"+data.list[i].orderList[j].list[m].deptCity+"("+data.list[i].orderList[j].list[m].deptCode+")"+"</td>"+
								"<td>"+data.list[i].orderList[j].list[m].arrCity+"("+data.list[i].orderList[j].list[m].arrCode+")"+"</td>"+
								"<td>"+data.list[i].orderList[j].list[m].deptDate+"</td>"+
								"<td>"+data.list[i].orderList[j].list[m].deptTime+"</td>"
						if(m==0){
							str+="<td rowspan="+length+">"+CommonConverter.toOrderBizStatusStr(data.list[i].orderList[j].orderStatus)+"</td>"+
								"<td rowspan="+length+">"+data.list[i].orderList[j].sellingPrice+"</td>"+
								"<td rowspan="+length+">"+data.list[i].orderList[j].purchQuantity+"</td>"+
								"<td rowspan="+length+">"+((data.list[i].orderList[j].sellingPrice)*(data.list[i].orderList[j].purchQuantity))+"</td>"
						}else{
							str+=""
						}	
						if(x==1){
							str+="<td rowspan="+length1*length+">"+tablebutton+"</td></tr>"
						}else{
							str+="</tr>"
						}
					}
					
				}
					
			}		
				
			$('table').append(str)
		})
		
	};
	
	//更多详情
	function moreDetail(conNo,conStatus,payOverTime){
		//alert(payOverTime)
		layer.open({
			type: 2,
			title: ['合同详情','background-color:#00B2EE; color:#fff;'],
			shadeClose: true,
			shade: 0.3,
			yes: function(index, layero) {
				layer.close(index);
			},
			btn2: function(index, layero) {
				//取消的回调
			},
			area: ['1200px', '1200px'],  
			content: ['${ctx}/np/lookMore?conNo='+conNo+'&conStatus='+conStatus+'&payOverTime='+payOverTime],  //iframe的url，no代表不显示滚动条
			success: function(layero, index){
				  layer.full(index);
			},
			end:function(){
				// localtion.reload();
			}
		});
	}
	//支付押金
	function payDeposit(conNo,deposit,payOverTime){
		//alert(payOverTime);
		var str={"deposit":deposit,"payOverTime":payOverTime};
		$.ajax({
			type:'post',
			//contentType:'application/json;charset=utf-8',
			url:'${ctx}/nporder/payDeposit/'+conNo,
			dataType:'json',
			data:str,
			success:function(json){//返回json结果
				//alert(json.msg);
				//window.location.href="${ctx}/np/contractQuery?temp="+Math.random();
				if(json.success){
					layer.alert('支付押金成功！'
				        	,{skin:'layui-layer-lan',title: ['系统提示', 'background-color:#00B2EE; color:#fff;'],closeBtn: 0}
				        	, function(index){
					        	getajax();
								layer.close(index);
							});
				}else{
					layer.alert(json.msg);
				}
				
			},
			error:function(msg){
		    	layer.alert("请检查您的网络连接，然后重试！");
		    }
		});
		layer.close(index);
	}
</script>
</head>
<body>
<div id='box'>	
	<div class='searchBox'>
			合同号：<input style='width:120px;' class="easyui-textbox" id="conNo" />
			合同状态：
			<select id="conStatus" style="width: 73px;">
				<option value="-1">全部</option>
                <option value="1">待审核</option>
                <option value="2">待支付</option>
                <option value="3">押金已收</option>
                <option value="4">合同中止</option>
                <option value="5">合同完成</option>
                <option value="6">合同退回</option>
                <option value="7">合同取消</option>
			</select>
			去程出发：
			<input type="text" value="" size="15" id="homecity_name" name="homecity_name" style="width:150px;height: 18px" mod="address|notice" mod_address_source="hotel" mod_address_suggest="" mod_address_reference="_startCity" mod_notice_tip="中文/拼音" />
			<input id="_startCity" name="_startCity" type="hidden" value="" />
			去程到达：
			<input type="text" value="" size="15" id="getcity_name" name="getcity_name" style="width:150px;height: 18px" mod="address|notice" mod_address_source="hotel"  mod_address_reference="_endCity" mod_notice_tip="中文/拼音" />
			<input id="_endCity" name="_endCity" type="hidden" value="" />
			出发时间 ：<input class="easyui-datebox" id="_startTime" style="width: 120px" />
			<button class='query' id="orderqueryBtn" >查询</button>
	</div>
		<table class='searchDetail' id="searchDetail" style="width: 100%;">
			<tr>
				<th>订单号</th>
				<th>航班号</th>
				<th>出发</th>
				<th>到达</th>
				<th>出发日期</th>
				<th>出发时刻</th>
				<th>状态</th>
				<th>单价（CNY）</th>
				<th>数量</th>
				<th>总价（CNY）</th>
				<th>操作</th>
			</tr>
		</table>
	<div class='pageing' style='position:relative;width:100%;height:30px;position:fixed;bottom:0;background:#f4f4f4;'>
	<div class='left'>
		<ul class='pageUl'>
			<li>
				<select class='pageSize' style='margin:5px 0 0 10px;height:20px;width:50px;border:1px solid #09a3dc;'>
					<option>5</option>
					<option>10</option>
					<option selected = "selected">20</option>
					<option>30</option>
					<option>40</option>
					<option>50</option>
					<option>100</option>
					<option>200</option>
					<option>300</option>
					<option>400</option>
					<option>500</option>
				</select>
			</li>
			<li class='firstPage' style='margin-top:7px;width:16px;height:16px;background:url(../image/pagepic.png) no-repeat;margin-left:20px;'></li>
			<li class='prePage' style='margin:7px 20px 0 0;width:16px;height:16px;background:url(../image/pagepic.png) -15px 0 no-repeat;margin-left:20px;'></li>
			<li style='margin-top:5px;font-size:12px;font-family:微软雅黑;'>第 <input class='pageNum' style='width:30px;height:20px;border:1px solid #09a3dc;text-align:center;' type='text' value='1'/> 共<span class='totalPage'></span> 页</li>
			<li class='nextPage' style='margin-top:7px;width:16px;height:16px;background:url(${ctx}/image/pagepic.png) -42px 0 no-repeat;margin-left:20px;'></li>
			<li class='lastPage' style='margin-top:7px;width:16px;height:16px;background:url(../image/pagepic.png) -48px 0 no-repeat;margin-left:20px;'></li>
			<li class='reflesh' style='margin-top:7px;width:16px;height:16px;background:url(../image/pagepic.png) -64px 0 no-repeat;margin-left:20px;'></li>
		</ul>
	</div>
	<div class='right' style='float:right;line-height:30px;font-size:12px;margin-right:20px;'>显示<span class='recordForm'></span>到<span class='recordTo'></span>，共<span class='totalRecord'></span>记录</div>
	</div>												
</div>
<script type="text/javascript" src="${ctx }/jslib/airport/fixdiv.js"></script>
<script type="text/javascript" src="${ctx }/jslib/airport/address.js"></script>
<jsp:include page="../footer.jsp"></jsp:include>
</body>
</html>